package BasicKnowledge.Basic.IO;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @time: 2021/2/2/002 15:59
 * @author: Zhurunhe
 */
public class Demo7 {
    public static void main(String[] args) {
        testFileWriter();

    }
    private static void testFileReader() {
        FileReader fileReader= null;
        try {
            fileReader = new FileReader("G:/abc.txt");
            char[] chars=new char[1024];
            int len=fileReader.read(chars);

            while (len!=-1){
                System.out.print(new String(chars,0,len));
                len=fileReader.read(chars);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileReader!=null){
                try {
                    fileReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    private static void testFileWriter() {
        FileWriter fileWriter= null;
        try {
            fileWriter = new FileWriter("G:/cde.txt");
            fileWriter.write("65");
            fileWriter.write("中国！！");
            char[] chars="嘎嘎嘎嘎嘎".toCharArray();
            fileWriter.write(chars,0,chars.length);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileWriter!=null){
                try {
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }


}
